
from django.shortcuts import render, redirect
from django_filters import OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.decorators import api_view
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView, RetrieveAPIView, ListAPIView
from rest_framework.response import Response

from blog.models import Article
from blog.serializer import ArticleSerializer


def index(request):

    return redirect('/static/html/home.html')



class ArticleView(ListCreateAPIView,RetrieveUpdateDestroyAPIView):
    '''文章视图'''
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer
    #筛选和排序
    # filter_backends = ( OrderingFilter)
    # filter_class = ArticleFilterSet
    ordering_fields = ('agood', )


    #重写get方法
    def get(self, request, *args, **kwargs):
        if 'pk' in kwargs:
            cls = RetrieveAPIView
        else:
            cls = ListAPIView
        return cls.get(self, request, *args, **kwargs)









